// main.cpp
#include <QGuiApplication>
#include <QQuickView>
#include <QQmlContext>
#include <QDateTime>
#include "applicationdata.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQuickView view;
    // 设置上下文属性
    view.rootContext()->setContextProperty("currentDateTime", QDateTime::currentDateTime());

    ApplicationData data;
    view.rootContext()->setContextProperty("applicationData", &data);

    view.setSource(QUrl("qrc:/main.qml"));
    view.setIcon(QIcon(":/logoApp.png"));
    view.setTitle(QStringLiteral("将C++对象嵌入到带有上下文属性的QML中"));
    view.show();

    return app.exec();
}
